<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>后端起步 | LinCMS-TP5入门</title>
    <meta name="generator" content="VuePress 1.5.0">
    
    <meta name="description" content="基于ThinkPHP 5.1的 Lin CMS 后端实现。">
    <link rel="preload" href="/lin-cms-book/assets/css/0.styles.e8c0fe6e.css" as="style"><link rel="preload" href="/lin-cms-book/assets/js/app.43f3ff7b.js" as="script"><link rel="preload" href="/lin-cms-book/assets/js/2.1c264783.js" as="script"><link rel="preload" href="/lin-cms-book/assets/js/10.b29049a1.js" as="script"><link rel="prefetch" href="/lin-cms-book/assets/js/11.5fc2ad3e.js"><link rel="prefetch" href="/lin-cms-book/assets/js/12.0fb72fc4.js"><link rel="prefetch" href="/lin-cms-book/assets/js/3.12364cb0.js"><link rel="prefetch" href="/lin-cms-book/assets/js/4.606d0aff.js"><link rel="prefetch" href="/lin-cms-book/assets/js/5.7bb207a9.js"><link rel="prefetch" href="/lin-cms-book/assets/js/6.1906fec0.js"><link rel="prefetch" href="/lin-cms-book/assets/js/7.2d983749.js"><link rel="prefetch" href="/lin-cms-book/assets/js/8.03718c42.js"><link rel="prefetch" href="/lin-cms-book/assets/js/9.2e1a8f4e.js">
    <link rel="stylesheet" href="/lin-cms-book/assets/css/0.styles.e8c0fe6e.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/lin-cms-book/" class="home-link router-link-active"><!----> <span class="site-name">LinCMS-TP5入门</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/lin-cms-book/" class="nav-link">
  简介
</a></div><div class="nav-item"><a href="/lin-cms-book/start/server_deploy.html" aria-current="page" class="nav-link router-link-exact-active router-link-active">
  入门
</a></div><div class="nav-item"><a href="/lin-cms-book/dev/" class="nav-link">
  开发文档
</a></div><div class="nav-item"><a href="/lin-cms-book/log/" class="nav-link">
  版本日志
</a></div><div class="nav-item"><a href="/lin-cms-book/qa/" class="nav-link">
  常见问题
</a></div><div class="nav-item"><a href="http://doc.cms.7yue.pro/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  林间有风
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="nav-item"><a href="https://github.com/ChenJinchuang/lin-cms-tp5" target="_blank" rel="noopener noreferrer" class="nav-link external">
  GitHub
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/lin-cms-book/" class="nav-link">
  简介
</a></div><div class="nav-item"><a href="/lin-cms-book/start/server_deploy.html" aria-current="page" class="nav-link router-link-exact-active router-link-active">
  入门
</a></div><div class="nav-item"><a href="/lin-cms-book/dev/" class="nav-link">
  开发文档
</a></div><div class="nav-item"><a href="/lin-cms-book/log/" class="nav-link">
  版本日志
</a></div><div class="nav-item"><a href="/lin-cms-book/qa/" class="nav-link">
  常见问题
</a></div><div class="nav-item"><a href="http://doc.cms.7yue.pro/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  林间有风
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="nav-item"><a href="https://github.com/ChenJinchuang/lin-cms-tp5" target="_blank" rel="noopener noreferrer" class="nav-link external">
  GitHub
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav>  <ul class="sidebar-links"><li><a href="/lin-cms-book/start/server_deploy.html" aria-current="page" class="active sidebar-link">后端起步</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/lin-cms-book/start/server_deploy.html#server-端必备环境" class="sidebar-link">Server 端必备环境</a></li><li class="sidebar-sub-header"><a href="/lin-cms-book/start/server_deploy.html#获取工程项目" class="sidebar-link">获取工程项目</a></li><li class="sidebar-sub-header"><a href="/lin-cms-book/start/server_deploy.html#安装依赖包" class="sidebar-link">安装依赖包</a></li><li class="sidebar-sub-header"><a href="/lin-cms-book/start/server_deploy.html#数据库配置" class="sidebar-link">数据库配置</a></li><li class="sidebar-sub-header"><a href="/lin-cms-book/start/server_deploy.html#导入数据" class="sidebar-link">导入数据</a></li><li class="sidebar-sub-header"><a href="/lin-cms-book/start/server_deploy.html#运行" class="sidebar-link">运行</a></li></ul></li><li><a href="/lin-cms-book/start/vue_deploy.html" class="sidebar-link">前端起步</a></li><li><a href="/lin-cms-book/start/server_demo.html" class="sidebar-link">后端上手</a></li><li><a href="/lin-cms-book/start/vue_demo.html" class="sidebar-link">前端上手</a></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="后端起步"><a href="#后端起步" class="header-anchor">#</a> 后端起步</h1> <h1 id="你需要了解"><a href="#你需要了解" class="header-anchor">#</a> 你需要了解</h1> <p>入门一个新框架最好的方式就是将这个框架的 demo 运行起来。由于 Lin 采用的是前后端分离的架构，所以相比于传统的网站，它的环境搭建会稍显麻烦。但 Lin 并没有采用任何冷门的技术，相比于传统网站，只不过多出了一些对于 Vue 运行环境的支持。</p> <p>Lin 的 Server 端是基于PHP的第三方开源框架 ThinkPHP 的, 所以你必须首先在自己的 PC 上安装 PHP 环境包。此外，Lin 是一个完整的框架，数据库是必然需要的。</p> <p>无需担心，我们将详细阐述安装的步骤，让你轻松将 Lin 运行起来。</p> <h1 id="快速开始"><a href="#快速开始" class="header-anchor">#</a> 快速开始</h1> <h2 id="server-端必备环境"><a href="#server-端必备环境" class="header-anchor">#</a> Server 端必备环境</h2> <ul><li><p>安装MySQL（version： 5.7+）</p></li> <li><p>安装PHP环境(version： 7.1+)</p></li></ul> <h2 id="获取工程项目"><a href="#获取工程项目" class="header-anchor">#</a> 获取工程项目</h2> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">git</span> clone https://github.com/ChenJinchuang/lin-cms-tp5.git
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><blockquote><p>执行完毕后会生成lin-cms-tp5目录</p></blockquote> <h2 id="安装依赖包"><a href="#安装依赖包" class="header-anchor">#</a> 安装依赖包</h2> <p>执行命令前请确保你已经安装了composer工具</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token comment"># 进入项目根目录</span>
<span class="token builtin class-name">cd</span> lin-cms-tp5
<span class="token comment"># 先执行以下命令，全局替换composer源，解决墙的问题</span>
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
<span class="token comment"># 接着执行以下命令安装依赖包</span>
composer <span class="token function">install</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><h2 id="数据库配置"><a href="#数据库配置" class="header-anchor">#</a> 数据库配置</h2> <p>Lin 需要你自己在 MySQL 中新建一个数据库，名字由你自己决定。例如，新建一个名为<code>lin-cms</code>的数据库。接着，我们需要在工程中进行一项简单的配置。使用编辑器打开 Lin 工程根目录下<code>/config/database.php</code>，找到如下配置项：</p> <div class="language-php line-numbers-mode"><pre class="language-php"><code><span class="token comment">// 服务器地址</span>
  <span class="token single-quoted-string string">'hostname'</span>        <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token single-quoted-string string">''</span><span class="token punctuation">,</span>
<span class="token comment">// 数据库名</span>
  <span class="token single-quoted-string string">'database'</span>        <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token single-quoted-string string">'lin-cms'</span><span class="token punctuation">,</span>
<span class="token comment">// 用户名</span>
  <span class="token single-quoted-string string">'username'</span>        <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token single-quoted-string string">'root'</span><span class="token punctuation">,</span>
<span class="token comment">// 密码</span>
  <span class="token single-quoted-string string">'password'</span>        <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token single-quoted-string string">''</span><span class="token punctuation">,</span>
  
  <span class="token comment">//省略后面一堆的配置项</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><p><strong>请务必根据自己的实际情况修改此配置项</strong></p> <h2 id="导入数据"><a href="#导入数据" class="header-anchor">#</a> 导入数据</h2> <p>接下来使用你本机上任意一款数据库可视化工具，为已经创建好的<code>lin-cms</code>数据库运行lin-cms-tp5根目录下的<code>schema.sql</code>文件，这个SQL脚本文件将为为你生成一些基础的数据库表和数据。</p> <h2 id="运行"><a href="#运行" class="header-anchor">#</a> 运行</h2> <p>如果前面的过程一切顺利，项目所需的准备工作就已经全部完成，这时候你就可以试着让工程运行起来了。在工程的根目录打开命令行，输入：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>php think run --port <span class="token number">5000</span> //启动thinkPHP内置的Web服务器
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>启动成功后会看到如下提示：</p> <div class="language-php line-numbers-mode"><pre class="language-php"><code>ThinkPHP Development server is started On <span class="token operator">&lt;</span>http<span class="token punctuation">:</span><span class="token comment">//127.0.0.1:5000/&gt;</span>
You can <span class="token keyword">exit</span> with `<span class="token constant">CTRL</span><span class="token operator">-</span><span class="token constant">C</span>`
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>打开浏览器，访问<code>http://127.0.0.1:5000</code>，你会看到一个欢迎界面，至此，Lin-cms-tp5部署完毕，可搭配<a href="https://github.com/TaleLin/lin-cms-vue" target="_blank" rel="noopener noreferrer">lin-cms-vue<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a>使用了。</p> <p>如果你安装时遇到问题，那么尝试看看常见问题汇总，看能否解决，或者去我们的 github 仓库看 issue。如果没有出现你的问题，请给我们提 issue。</p></div> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">最后更新时间:</span> <span class="time">10/7/2020, 11:20:01 PM</span></div></footer> <div class="page-nav"><p class="inner"><!----> <span class="next"><a href="/lin-cms-book/start/vue_deploy.html">
        前端起步
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"></div></div>
    <script src="/lin-cms-book/assets/js/app.43f3ff7b.js" defer></script><script src="/lin-cms-book/assets/js/2.1c264783.js" defer></script><script src="/lin-cms-book/assets/js/10.b29049a1.js" defer></script>
  </body>
</html>
